package com.chinasofti.etc.alcohol.service.impl;





import com.chinasofti.etc.alcohol.dao.model.Commodity;
import com.chinasofti.etc.alcohol.dao.CommodityMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinasofti.etc.alcohol.dao.model.Type;
import com.chinasofti.etc.alcohol.service.ICommodityService;
import com.chinasofti.etc.alcohol.service.info.TypeInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lucas
 * @since 2019-05-29
 */
@Service
@Slf4j
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements ICommodityService {


    @Autowired
    private CommodityMapper commodityMapper;



    @Override
    public List<Commodity> toOne(){
        List<Commodity> commodities=new ArrayList<>();
        String[] str={"葡萄酒","洋酒","啤酒"};
        for(int i=0;i<str.length;i++){
            Commodity commodity=commodityMapper.toOne(str[i]);
            commodities.add(commodity);
        }
        return commodities;
    }



    @Override
    public List<Commodity> newSorting() {
        return commodityMapper.newSorting();
    }

    @Override
    public List<Commodity> salesRanking(String name) {

        return commodityMapper.salesRanking(name);
    }

    @Override
    public List<Commodity> getBrand(TypeInfo typeInfo) {
        Type type=new Type();
        BeanUtils.copyProperties(typeInfo,type);
        List<Commodity> list=commodityMapper.query(type);
        return list;
    }

    @Override
    public Integer getCount(TypeInfo typeInfo) {
        Type type=new Type();
        BeanUtils.copyProperties(typeInfo,type);

        if(type.getBrand()!=null){
            type.setBrand(type.getBrand().trim());
        }
        if(type.getAll()!=null){
            type.setAll(type.getAll().trim());
        }
        if(type.getOrigin()!=null){
            type.setOrigin(type.getOrigin().trim());
        }
        Integer i=commodityMapper.queryCount(type);
        return i;
    }

    @Override
    public Commodity getInfo(String commodityNumber) {
        return commodityMapper.getInfo(commodityNumber);
    }
}
